#ifndef __HX6202SYS_H
#define __HX6202SYS_H		

#include "stm32f4xx.h"
#include "eeprom.h"
#include "sys.h"

//参数选择
#define SELECT_VALUE(value1, value2) ((HX6203.ControlBit) ? (value1) : (value2))

#define AMP_GateVoltage -5.0f
//频率源推动上限
#define MaxSeedVbias 3.0f
//功率上限
#define P_UpLimit 7200
//功率保护下限
#define P_Protect_Debug		4000
#define P_Protect_Factory	0
//功率初值
#define P_InitValue 500
//功率自动调整时限
#define P_AutoTimeLimit 3600
//功率变化梯度
#define P_Gradient 450
//功率稳定计时上限
#define P_StableCount 2
//功率变化率上限(10%)
//#define P_Standard 10000
#define P_Standard (HX6203.AimRF*0.02f)
//功率映射值
#define P_MapValue 6000	//(PowerSetValue / P_MapValue)

#define SeedDebugPrint 0
//偏置平衡修正，若启用，将微调控制后级PA平均偏压
#define BiasBalanceFix 0

#define AMP_NUM 9
#define PA_NUM 3
#define AMP_DISABLE 0x01ff

//NodeState 状态
#define NORMAL      0      //正常 绿色
#define ABNORMAL    1      //异常 红色

//开关状态定义
enum SwitchType
{
    ON,
    OFF
};

//PA模块状态结构体
struct PA_StateType
{
	float Curr;		
	float Temp;
	unsigned int PD;
	float Vbias;
	unsigned int CommErr;
};

//刀片单元状态结构体
struct AMPUnit_StateType
{
	struct PA_StateType PA[PA_NUM];
	float FwdRF;
	float RevRF;
	float AimRF;
	float Vneg;
	float MaxTemp;
	unsigned int CommErr;
	enum SwitchType STA;
};

//整机状态结构体
struct HX6203_StateType
{
	struct AMPUnit_StateType AMP[AMP_NUM];
	float FwdRF, FwdMap;
	float RevRF;
	float AimRF;
	float LastAimRF;
    float PATempMax, PATempMin;
	struct PA_StateType Preamp[2];	//前放PA
	enum SwitchType STA;
	enum SwitchType LastSTA;
    
    uint8_t DebugMode;
    uint8_t AMP_GateV_Flag;
    uint16_t AMP_STA;   //刀片使能状态 置1：使能失败
    uint32_t StateBit;  //上报给工业屏的整机状态位
	
	uint8_t ControlBit; //控制标志位，1使用自定义参数，0使用宏参数
	int8_t SetCountdown;
	eeprom_data_t EEPROMdata;
};

struct Seed_StateType{
	float Curr;
	float Vbias;
	unsigned int PD;
};

extern struct HX6203_StateType HX6203;
extern struct Seed_StateType Seed;
extern unsigned int HX6203_Protect;

#endif  

